<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="com.zlgs.cqyf.vote.ConnectionUtil"%>
<%@page import="weaver.conn.RecordSet"%>
<%@page import="com.alibaba.fastjson.JSONObject"%>
<%@ page import="java.io.PrintWriter" %>
<%@ page import="java.io.IOException" %>
<%
    response.setCharacterEncoding("UTF-8");
    response.setContentType("application/json; charset=utf-8");
	    JSONObject retObject = new JSONObject();
	try{
		retObject.put("code", 200);
		retObject.put("msg", "操作成功");
    	// URL 参数
	    Object name  = request.getParameter("name");              // 奖项名称
	    Object startTime  = request.getParameter("startTime");    // 开始时间
	    Object endTime  = request.getParameter("endTime");        // 结束时间
	    Object dateType  = request.getParameter("dateType");      // 时间类型：1 年度 2 季度
	    Object createType  = request.getParameter("createType");  // 创建类型：1 BMP 2 OA
	    Object about  = request.getParameter("about");             // 活动介绍
	    Object regular  = request.getParameter("regular");        // 活动规则
	    Object votes  = request.getParameter("votes");             // 投票规则：活动每人N票
	    Object votesSame  = request.getParameter("votessame");     // 投票规则：同一个人允许投N票
 
	    // 插入数据
	    String sql = "INSERT INTO vote_awards(" +
	            (name==null?"":"name, ") +
	            (startTime!=null?"start_time, ":"") +
	            (endTime!=null?"end_time, ":"") +
	            (dateType!=null?"date_type, ":"") +
	            (createType!=null?"create_type, ":"") +
	            (about!=null?"about, ":"") +
	            (regular==null||regular.equals("")?"":"regular, ") +
	            (votes!=null?"votes, ":"") +
	            (votesSame!=null?"votes_same, ":"") +
	            "create_time) " +
	            "values(" +
	            (name==null?"":"N'"+name+"', ") +
	            (startTime==null?"":"'"+startTime+"', ") +
	            (endTime==null?"":"'"+endTime+"', ") +
	            (dateType==null?"":dateType+", ") +
	            (createType==null?"":createType+", ") +
	            (about==null?"":"N'"+about+"',") +
	            (regular==null||regular.equals("")?"":("N'"+regular+"',")) +
	            (votes==null?"":votes+", ") +
	            (votesSame==null?"":votesSame+",") +
	            "GETDATE())";
	    	 RecordSet set = new RecordSet();
	    	 set.executeSql(sql);
    } catch (Exception e) {
        e.printStackTrace();
        retObject.put("code", -1);
        retObject.put("msg", e.getMessage());
    } finally {
		PrintWriter printWriter = response.getWriter();
		printWriter.append(retObject.toJSONString());
        if (printWriter != null) printWriter.close();
    }
%>
